package com.boilerCloud.controller.device;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.device.DeviceInfo;
import com.boilerCloud.dto.device.DeviceWarnInfo;
import com.boilerCloud.dto.sys.ReqResult;
import com.boilerCloud.service.device.IDeviceWarnService;


@RestController
@RequestMapping("/device/")
public class DeviceWarnControler {
	private static final Logger log = LoggerFactory.getLogger(DeviceWarnControler.class);
	@Resource
	private IDeviceWarnService deviceWarnService;


	@RequestMapping(value = "deviceWarnList")
	public ModelAndView deviceWarnList() {
		return new ModelAndView("/views/device/deviceWarnInfo.html");
	}
	@RequestMapping(value = "deviceWarnRecordList")
	public ModelAndView deviceWarnRecordList() {
		return new ModelAndView("/views/device/deviceWarnRecordInfo.html");
	}
	

	/**
	 * 查询设备列表
	 * @param grade
	 * @param yema
	 * @param length
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "qryDeviceWarnList", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult qryDeviceList(@ModelAttribute DeviceWarnInfo device ,
			@RequestParam(required = true) int yema,
			@RequestParam(required = true) int length,HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			
			HzlqswPage<DeviceWarnInfo> page = new HzlqswPage<DeviceWarnInfo>();
			page.setCurPage(yema);
			page.setPageSize(length);
			deviceWarnService.qryList(device,page);
			rst.setReturnObject(page);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("查询设备列表失败");
			log.error("查询设备列表异常",e);
			return rst;
		}
	}
	
	/**
	 * 修改设备信息
	 * @param device
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "editDevice1", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult editDevice(
			@ModelAttribute DeviceInfo device ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			deviceWarnService.edit(device);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("修改设备信息失败");
			log.error("修改设备信息异常",e);
			return rst;
		}
	}
	/**
	 * 新增设备
	 * @param device
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addDevice1", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult addDevice(
			@ModelAttribute DeviceInfo device ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			deviceWarnService.addDevice(device);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("新增设备信息失败");
			log.error("新增设备信息异常",e);
			return rst;
		}
	}
	
	/**
	 * 删除设备
	 * @param businessNo
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "delDevice1", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult delDevice(
			@RequestParam(required = true) int id,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			deviceWarnService.delDevice(id);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("删除设备失败");
			log.error("删除设备异常",e);
			return rst;
		}
	}
	
	/**
	 * 获取设备信息
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getDeviceInfo1", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult getDeviceInfo(
			@RequestParam(required = true) int id,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			DeviceInfo device  = deviceWarnService.getDeviceInfo(id);
			rst.setResultCode(ReqResult.resultCode_Success);
			rst.setReturnObject(device);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("删除设备失败");
			log.error("删除设备异常",e);
			return rst;
		}
	}
	


	

	

}
